package com.springboot.mongo.controller;

import com.springboot.mongo.bean.User;
import com.springboot.mongo.service.UserMongoService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserMongoService userService;

    // 添加单个用户
    @PostMapping
    public User addUser(@RequestBody User user) {
        return userService.saveUser(user);
    }

    // 添加多个用户
//    @PostMapping("/batch")
//    public Iterable<User> addUsers() {
//        User user1 = new User("Alice", 25);
//        User user2 = new User("Bob", 30);
//        return userService.saveUsers(Arrays.asList(user1, user2));
//    }
}